<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>继承对constructor属性的影响</title>
</head>
<body>
    <script>
        let User = function(){};
        User.prototype.name = function(){
            console.log('User原型中的name方法');
        }

        let Member = function(){};
        // Member.prototype = Object.create(User.prototype);
        // // 因为Object.create()是重新创建了一个Member.prototype，它里面没有constructor，但它的原型User.prototype中有constructor为User
        // console.dir(Member.prototype.constructor);  //User

        // 我们可以创建Member.prototype时，给它加上constructor
        Member.prototype = Object.create(User.prototype);

        // 第一中添加方式有bug
        // Member.prototype.constructor = Member;
        // console.log(Object.getOwnPropertyDescriptors(Member.prototype));    //enumerable为true,可遍历的
        // for (const key in Member.prototype) {
        //     console.log(key);   //这时候遍历，它的constructor也会被遍历出来
        // }

        // 第二种添加方式
        Object.defineProperty(Member.prototype,"constructor",{
            value:Member,
            enumerable:false
        });
        for (const key in Member.prototype) {
            console.log(key);   //这时候遍历，它的constructor不会被遍历出来
        }

        console.dir(Member.prototype.constructor);  //Member

        let member1 = new Member.prototype.constructor;
        let member2 = new member1.__proto__.constructor;
        member1.name();
        member2.name();
    </script>
</body>
</html>